package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysBackApply;
import com.ruoyi.system.service.ISysBackApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 赎回申请Controller
 * 
 * @author paul
 * @date 2023-06-25
 */
@RestController
@RequestMapping("/apply")
public class SysBackApplyController extends BaseController
{
    @Autowired
    private ISysBackApplyService sysBackApplyService;

    /**
     * 查询赎回申请列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBackApply sysBackApply)
    {
        startPage();
        List<SysBackApply> list = sysBackApplyService.selectSysBackApplyList(sysBackApply);
        return getDataTable(list);
    }

    /**
     * 导出赎回申请列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "赎回申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBackApply sysBackApply)
    {
        List<SysBackApply> list = sysBackApplyService.selectSysBackApplyList(sysBackApply);
        ExcelUtil<SysBackApply> util = new ExcelUtil<SysBackApply>(SysBackApply.class);
        util.exportExcel(response, list, "赎回申请数据");
    }

    /**
     * 获取赎回申请详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysBackApplyService.selectSysBackApplyById(id));
    }

    /**
     * 新增赎回申请
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "赎回申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBackApply sysBackApply)
    {
        return toAjax(sysBackApplyService.insertSysBackApply(sysBackApply));
    }

    /**
     * 修改赎回申请
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "赎回申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBackApply sysBackApply)
    {
        return toAjax(sysBackApplyService.updateSysBackApply(sysBackApply));
    }

    /**
     * 删除赎回申请
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "赎回申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBackApplyService.deleteSysBackApplyByIds(ids));
    }
}
